#!/usr/bin/env python

import setuptools
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

import os
import sys
import numpy
import platform

i23_version=os.environ['VERSION']
if  i23_version == '':
    print("Please set the environmental variable VERSION")
    sys.exit(1)

library_include_path = ""
library_lib_path = ""
try:
    library_include_path = os.environ['LIBRARY_INC']
    library_lib_path = os.environ['LIBRARY_LIB']
except:
    library_include_path = os.environ['PREFIX']+'/include'
    pass

extra_include_dirs = [numpy.get_include(), library_include_path]
#extra_library_dirs = [os.path.join(library_include_path, "..", "lib")]
extra_compile_args = []
extra_library_dirs = [library_lib_path]
extra_compile_args = []
extra_link_args = []
extra_libraries = ['i23seg']

print ("extra_library_dirs " , extra_library_dirs)

extra_include_dirs += [os.path.join(".." , "Core"),
                       os.path.join(".." , "Core",  "functions_CPU"),
						   "."]

if platform.system() == 'Windows':
    extra_compile_args[0:] = ['/DWIN32','/EHsc','/DBOOST_ALL_NO_LIB' , '/openmp' ]
else:
    extra_compile_args = ['-fopenmp','-O2', '-funsigned-char', '-Wall', '-std=c++0x']
    extra_libraries += [@EXTRA_OMP_LIB@]

setup(
    name='i23seg',
	description='i23 segmentation module',
	version=i23_version,
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("i23.methods.segmentation",
                             sources=[os.path.join("." , "src", "cpu_segmentation.pyx") ],
                             include_dirs=extra_include_dirs,
							 library_dirs=extra_library_dirs,
							 extra_compile_args=extra_compile_args,
							 libraries=extra_libraries ),

    ],
	zip_safe = False,
	packages = {'i23', 'i23.methods'},
)
